package com.bsj.power.pls.config.net.netty.common;

import com.bsj.consumerQ.until.ExceptionUntil;
import com.bsj.power.pls.config.net.netty.AnalysisData;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @author yinhao
 * @version 1.0
 * @description 解码
 * @date 2024/9/23
 */
@Slf4j
public class Decoder extends ByteToMessageDecoder {

    private AnalysisData analysisData;

    public Decoder(AnalysisData now) {
        this.analysisData = now;
    }

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext,
                          ByteBuf byteBuf, List<Object> list) throws Exception {
        try {
            analysisData.decode(byteBuf, list);
        } catch (Exception e) {
            log.error("数据解析失败: {}", ExceptionUntil.getErrorStr(e));
        }
    }
}
